
import React, { useEffect, useState } from 'react';
import { Button, Input,Space, Table, Tag } from 'antd';
import './index.less'

const columns = [
  {
    title: 'Name',
    dataIndex: 'name',
    key: 'name',
    render: (text:any) => <a>{text}</a>,
  },
  {
    title: 'Age',
    dataIndex: 'age',
    key: 'age',
  },
  {
    title: 'Address',
    dataIndex: 'address',
    key: 'address',
  },
  {
    title: 'Tags',
    key: 'tags',
    dataIndex: 'tags',
    render: (_, { tags }) => (
      <>
        {tags.map((tag:any) => {
          let color = tag.length > 5 ? 'geekblue' : 'green';
          if (tag === 'loser') {
            color = 'volcano';
          }
          return (
            <Tag color={color} key={tag}>
              {tag.toUpperCase()}
            </Tag>
          );
        })}
      </>
    ),
  },
  {
    title: 'Action',
    key: 'action',
    render: (_, record:any) => (
      <Space size="middle">
        <a>Invite {record.name}</a>
        <a>Delete</a>
      </Space>
    ),
  },
];
const data = [
  {
    key: '1',
    name: 'John Brown',
    age: 32,
    address: 'New York No. 1 Lake Park',
    tags: ['nice', 'developer'],
  },
  {
    key: '2',
    name: 'Jim Green',
    age: 42,
    address: 'London No. 1 Lake Park',
    tags: ['loser'],
  },
  {
    key: '3',
    name: 'Joe Black',
    age: 32,
    address: 'Sydney No. 1 Lake Park',
    tags: ['cool', 'teacher'],
  },
];
for(let i = 0;i<100;i++){
	data.push( {
		key: '1'+i,
		name: 'John Brown',
		age: 32,
		address: 'New York No. 1 Lake Park',
		tags: ['nice', 'developer'],
	})
}


const OldReact = () => {
	let [key, setKey] = useState("")
	const goToSearch = () => {
		console.log("点击了搜索按钮", key)
	}
	useEffect(()=>{
		console.log('old-react的mounted')
		return ()=>{

		}
	},[])
	return (
		<>
			<div className='search-box'>
				<Input 
					className='key-inp'
				 	placeholder="请输入..." 
				 	value={key} 
					onChange={(e)=>setKey(e.target.value)}
				 />
				<Button
					className='search-btn'
					type="primary"
					onClick={goToSearch}
				>
					查询
				</Button>
			</div>
			<div className='table-box'>
				<Table style={{height:"100%"}} columns={columns} dataSource={data} />
			</div>
		</>
	);
};

export default OldReact;
